
package models.spider.parser.aaa;

import java.util.ArrayList;
import java.util.List;

import models.aaa.Asset;
import models.spider.ISpider;
import models.spider.parser.IParser;
import models.spider.request.Request;

/**
 * 
 * @see tika
 * @author laurent@opprecht.info
 */
public class Parser implements IParser {

    protected IParser rdf  = null;
    protected IParser json = null;

    public Parser() {
        rdf = new models.spider.parser.aaa.rdf.Parser();
        json = new models.spider.parser.aaa.json.Parser();
    }

    @Override
    public List<Asset> parse(final Request request, final ISpider spider) {
        List<Asset> result = new ArrayList<Asset>();

        if (!request.isValid()) {
            Asset item = Asset.get(request.getUrl());
            item.setValid(false);
            result.add(item);
            return result;
        }

        result = rdf.parse(request, spider);
        if (!result.isEmpty()) {
            return result;
        }
        result = json.parse(request, spider);
        return result;

    }
}
